package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ObjectUsedByThreadsOnTheSameTime {

	public static void main(String[] args) {
		Person person = new Person();
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
						System.out.println(Thread.currentThread().getName());
						person.listen();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		},"l_1").start();
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					person.speak();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		},"s_1").start();
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
						System.out.println(Thread.currentThread().getName());
						person.listen();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		},"l_2").start();
	}
	
	Thread one = new Thread();
	ExecutorService ll = Executors.newFixedThreadPool(5);
}

class Person{
	public void speak() throws InterruptedException{
		System.out.println("speak begin");
		Thread.sleep(3000);
		System.out.println("speak end");
	}
	public void listen() throws InterruptedException {
		for(;;) {
			Thread.sleep(1000);
			System.out.println("I am listening all the time");
		}
	}
}
